package com.example.c5;

import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.DefaultPromise;

import java.util.concurrent.ExecutionException;

/**
 * @author Jonathan
 * 2021/6/2 23:47
 */
public class PromiseDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        EventLoop next = new NioEventLoopGroup().next();
        DefaultPromise<Object> promise = new DefaultPromise<>(next);
        new Thread(() -> {
            try {
//                int i = 1 / 0;
                Thread.sleep(1000);
                promise.setSuccess(1000);
            } catch (Exception e) {
                e.printStackTrace();
                promise.setFailure(e);
            }
        }).start();
        System.out.println(promise.get());
    }
}
